package com.working.libbase.initializer

import android.app.Activity
import android.content.Context
import android.view.Menu
import androidx.navigation.NavGraphBuilder
import androidx.startup.Initializer
import com.alibaba.android.arouter.launcher.ARouter
import org.koin.core.context.loadKoinModules
import org.koin.core.module.Module

abstract class ModuleInitializer : Initializer<Unit> {

    private val applicationProvider =
        ARouter.getInstance().navigation(ApplicationProvider::class.java)

    open val isRootModule: Boolean = false

    abstract val entranceClass: Class<Activity>

    override fun create(context: Context) {
        applicationProvider.addDestination(provideDestination())
        applicationProvider.addMenu(provideMenu())
        loadKoinModules(provideModules())
    }

    abstract fun provideDestination(): NavGraphBuilder.() -> Unit

    abstract fun provideMenu(): Menu.() -> Unit

    abstract fun provideModules(): List<Module>

    override fun dependencies(): MutableList<Class<out Initializer<*>>> =
        mutableListOf(AppInitializer::class.java)

}